package com.winning.bdu.collect.controller;

import com.alibaba.fastjson.JSON;
import com.winning.bdu.collect.commons.CollectResponse;
import com.winning.bdu.collect.commons.Constant;
import com.winning.bdu.collect.service.CollectService;
import com.winning.bdu.collect.service.IJdbcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * Author: yanxf@winning.com.cn
 * Description: 采集接口控制层
 * Date 2019/5/24 19:51
 */

@RestController
@Slf4j
public class CollectController {

    @Resource
    private CollectService collectService;

    @RequestMapping("/collect")
    public String map(@RequestParam String tableName) {
        /*HashMap hashMap = new LinkedHashMap();
        try {
            List<Map<String, Object>> list = iJdbcService.getPageList(tableName, 1, 10);
            hashMap.put("code", 200);
            hashMap.put("rows", list.size());
            hashMap.put(tableName, list);
        } catch (DataAccessException e) {
            log.error("查询表:{}失败，失败原因{}", tableName, e);
            hashMap.put("code", 500);
            hashMap.put("rows", null);
            hashMap.put(tableName, new ArrayList<>());
        } finally {

        }
        return hashMap;*/


        collectService.collectTables( "student" );
        log.info("tablename:" + tableName);
        CollectResponse collectResponse = new CollectResponse();
        collectResponse.setStatuscode(Constant.RESP_SUCC);
        collectResponse.setRespmsg("请求成功1");
        return JSON.toJSONString(collectResponse);
    }
}
